package Panel;
/**
 * Created by win10 on 2017/6/12.
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;


public class StatusBar extends JPanel
{
    //添加 显示时间的JLabel
    public  StatusBar(){
        JLabel time = new JLabel();
        add(time);
        this.setTimer(time);
    }
    private void setTimer(JLabel time){
        final JLabel varTime = time;
        Timer timeAction = new Timer(1000, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                long timemillis = System.currentTimeMillis();
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                varTime.setText(df.format(new Date(timemillis)));
            }
        });
        timeAction.start();
    }

    //运行方法
    public static void main(String[] args) {
        StatusBar timeFrame = new StatusBar();
        timeFrame.setSize(160, 80);

        timeFrame.setVisible(true);

    }
}